<template>
  <div>
    <el-card class="box-card">
      <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
      <div ref="main" style="width: 800px; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { TheLineChart } from "../../http/api";
export default {
  data() {
    return {
      initData: {//合并的选项
        color: ["#C23531", "#2F4554", "#61A0A8", "#D48265", "#91C7AE"],
        title: {
          text: "用户来源",
        },
        tooltip: {
          backgroundColor: "rgba(0,0,0,0.5)",
          color: "#ffff",
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
          textStyle: {
            color: "#fff", //设置文字颜色
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  mounted() {
    this.getEcharts();
  },
  methods: {
    async getEcharts() {
      //创建化Echrts对象
      let myChart = echarts.init(this.$refs.main);
      //调用图表配置接口并返回图表配置数据
      const option = await TheLineChart();
      //合并图表初始数据和从接口返回的数据，合并
      let optionData = { ...this.initData, ...option };

      //指定配置给myChart图表对象
      myChart.setOption(optionData);
    },
  },
};
</script>

<style>
</style>